﻿$(document).ready(function(){
	/*** 初始化 ***/
	//ajax请求时的加载状态
	$(window).ajaxSend(function(evt, request, settings){
		look.loader.show();
	}).ajaxComplete(function(event, request, settings){
		look.loader.hide();
	});
	
	//监视hash
	try{
		$(window).hashchange(function(){
			look.loadFn();
		});
		$(window).hashchange();
	}catch(e){}
	
	$(window).resize(function(){
		publicInit.layout();
	});
	publicInit.layout();
});

var publicInit = {
	headerLoader : function(){
		if($("#header").children().length == 0){
			loadPage("#header","html/public/header.html");
		}
		$("#exitSubset").attr("href", "http://106.187.89.39:8010/action/user,logOut.php?backUrl=" + look._SITE_DOMAIN + "/local/user/login");
	},
	menuSet : function(){
		if(look.getHashParam("type")){
			$("#navPanel a").removeClass("selected");
			$("#navPanel a[type='" + look.getHashParam("type") + "']").addClass("selected").parents("ul").attr("show", true).show().prev("li").addClass("open");
		}
	},
	menuLoader : function(){
		if($("#navPanel ul").children().length == 0){
			loadPage("#nav","html/public/menu.html");
			$(".look_tree").looktree();
			publicInit.menuSet();
		}
	},
	menuDateSet : function(){
		//菜单设置日期
		var to = look.getLocalDate(),
			from = look.getLastMonthDate(to);
		$("#navPanel a").each(function(i){
			if($(this).attr("href") != "javascript:"){
				var hashString = $(this).attr("href").split("#")[1] ? $(this).attr("href").split("#")[1] : $(this).attr("href");
				
				if(look.getStringParam("theme", hashString) == "data"){
					$(this).attr("href", "#" + look.setParam([["from", from], ["to", to]], hashString));
				}
			}
		});
	},
	layout : function(){
		var wWidth = parseInt($(window).width());
		var wHeight = parseInt($(window).height());
		var hHeight = parseInt($(".header").height());
		var fHeight = parseInt($(".footer").height());
		var contentHeight = wHeight - hHeight - fHeight;
		$("#main").css({height: contentHeight});
		$("#wrapper").css({height: contentHeight - $("#topBar").height()});
		$("#nav").css("height", contentHeight + 2);
		$("#navPanel").css("height", contentHeight - 20);

		$("#loader").css("left", (wWidth - 32) / 2);
	},
	setBreadcrumb : function(title){
		$("#breadcrumb .breadcrumb_cell").remove();
		var lastClass="";
		for(var i = 0; i < title.split(",").length; i++){
			$("#breadcrumb").append(
				'<span class="breadcrumb_cell">' +
				'	<a href="javascript:" class="breadcrumb_link">' + title.split(",")[i] + '<span class="breadcrumb_arrow"></span>' + '</a>' +
				'</span>'
			);
		}
		$("#breadcrumb .breadcrumb_arrow:last").addClass("last");
	},
	inputStyle : function(){
		$(".text,textarea").live("mouseenter", function(){
			$(this).addClass("hover");
			return false;
		}).live("mouseleave", function(){
			$(this).removeClass("hover");
			return false;
		}).live("focus", function(){
			$(this).addClass("selected");
		}).live("blur", function(){
			$(this).removeClass("selected");
		});
	},
	tabelStyle : function(){
		$("table tr:even").addClass("even");
		$("table tr").bind("mouseenter mouseleave", function(){
			$(this).toggleClass("hover");
		});
	}
}